package com.ruoyi.caigou.service.impl;

import com.ruoyi.caigou.mapper.BuyerReportMapper;
import com.ruoyi.caigou.service.IBuyerReportService;
import com.ruoyi.caigou.utils.JasperPdfUtil;
import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.system.api.domain.report.BuyerReport;
import net.sf.jasperreports.engine.JRException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.FileNotFoundException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 采购员统计Service业务层处理
 *
 * @author ry
 * @date 2024-11-08
 */
@Service
public class BuyerReportServiceImpl implements IBuyerReportService {
    @Autowired
    private BuyerReportMapper buyerReportMapper;

    /**
     * 查询采购员统计列表
     *
     * @param buyerReport 采购员统计
     * @return 采购员统计
     */
    @Override
    public List<BuyerReport> selectBuyerReportList(BuyerReport buyerReport) {
        return buyerReportMapper.selectBuyerReportList(buyerReport);
    }

    /**
     * @return byte[]
     * @description 采购员统计打印
     * @date 2024/11/15 下午2:17
     **/
    public byte[] printBuyerReport(BuyerReport buyerReport) throws JRException, FileNotFoundException {
        String templatePath = "jasper/BuyerReport.jrxml";
        Map<String, Object> paramsMap = new HashMap<>();
        paramsMap.put("createBy", SecurityUtils.getUsername());
        List<BuyerReport> list = buyerReportMapper.selectBuyerReportList(buyerReport);
        return JasperPdfUtil.exportPdfFromXml(templatePath, paramsMap, list);
    }
}
